﻿<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
    <title>综合治税GISAPP-后台管理中心</title>   
    <link rel="stylesheet" href="Content/src/css/layui.css" media="all">
    <link rel="stylesheet" href="Content/css/global.css"> 

</head>
<body>
<div class="layui-layout layui-layout-admin">
    <!--头部代码（旧版本）-->
    <div class="layui-header header">
      <div class="layui-main">
        <a class="logo"  target="_blank">
            <img src="Content/images/logo-top.png" alt="智税">
        </a>
        <div class="top_admin_user">
            <a id="username" ></a>   | <a class="demo">修改密码</a>  | <a class="logout_btn" href="javascript:void(0)">退出</a>
        </div>
      </div>
    </div>
    <!--头部代码（旧版本）-->

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree left_menu_ul">
                <li class="layui-nav-item layui-nav-title">
                    <a>菜单列表</a>
                </li>
                <li class="layui-nav-item first-item layui-this" id="news">
                    <a href="./notice_list.html" target="main">
                        <i class="layui-icon">&#xe638;</i>
                        <cite>通知公告</cite>
                    </a>
                </li>
                <li class="layui-nav-item" id="system">
                    <a href="./laws_list.html" target="main">
                        <i class="layui-icon">&#xe627;</i>
                        <cite>制度查询</cite>
                    </a>
                </li>
                <li class="layui-nav-item" id="workflow">
                    <a href="./flow_list.html" target="main">
                        <i class="layui-icon">&#xe61d;</i>
                        <cite>办事流程</cite>
                    </a>
                </li>
                <li class="layui-nav-item" id="house">
                    <a href="./push_list.html" target="main">
                        <i class="layui-icon">&#xe63b;</i>
                        <cite>房屋审批</cite>
                    </a>
                </li>
                <li class="layui-nav-item" id="houseInfo">
                    <a href="./pushcard_list.html" target="main">
                        <i class="layui-icon">&#xe63b;</i>
                        <cite>租房审批</cite>
                    </a>
                </li>
                <li class="layui-nav-item " id="user">
                    <a href="./user_list.html" target="main">
                        <i class="layui-icon">&#xe613;</i>
                        <cite>用户管理</cite>
                    </a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body iframe-container">
        <div class="iframe-mask" id="iframe-mask"></div>
        <iframe class="admin-iframe" id="admin-iframe" name="main" src="./notice_list.html"></iframe>
    </div>
</div>

    <div id="add_edit" style="display: none;padding: 20px;">
        <form class="layui-form">
            <div class=" layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-block">
                    <input type="password" id="oldepass" lay-verify="var_oldepass" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password" id="newpass" lay-verify="var_newpass" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" id="agenpass" lay-verify="var_agenpass" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="text-align: right;">
                <div class="layui-btn layui-btn-normal" lay-submit lay-filter="btnAddRole">提 交</div>
            </div>
        </form>
    </div>

    <script type="text/javascript" src="Content/src/layui.js"></script>
    <script type="text/javascript">
        layui.use(['element', 'layer', 'form', 'layedit'], function () {
            var element = layui.element()
            , jq = layui.jquery
            , form = layui.form()
            , layedit = layui.layedit
            , laypage = layui.laypage;

            //加载
            jq(document).ready(function () {
                if (localStorage.getItem("username") == "" || localStorage.getItem("username") == null) {
                    window.location.href = "login.html";
                } else
                {
                    document.getElementById('username').innerHTML = localStorage.getItem("username");
                    if (localStorage.getItem("dtparentId") == "0") {
                        document.getElementById("news").style.display = "inline";
                        document.getElementById("system").style.display = "inline";
                        document.getElementById("workflow").style.display = "inline";
                        document.getElementById("house").style.display = "inline";
                        document.getElementById("houseInfo").style.display = "inline";
                        document.getElementById("user").style.display = "inline";
                    } else {
                        document.getElementById("news").style.display = "none";
                        document.getElementById("system").style.display = "none";
                        document.getElementById("workflow").style.display = "none";
                        document.getElementById("house").style.display = "inline";
                        document.getElementById("houseInfo").style.display = "inline";
                        document.getElementById("user").style.display = "none";
                    }
                }
            });

            jq('.demo').on('click', function () {
                layer.open({
                    title: '修改密码',
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['500px', '330px'],
                    content: jq('#add_edit'),
                    success: function () {
                    }
                });
            });
            
            //退出
            jq('.logout_btn').on('click', function () {
                localStorage.clear("username");
                localStorage.clear("userid");
                window.location.href = "login.html";
            });

            form.verify({
                var_oldepass: [/^[\S]{6,12}$/, '旧密码必须6到12位，且不能出现空格'],
                var_newpass: [/^[\S]{6,12}$/, '新密码必须6到12位，且不能出现空格'],
                var_agenpass: [/^[\S]{6,12}$/, '确认密码必须6到12位，且不能出现空格']
            });

            //监听提交- 修改密码（提交）
            form.on('submit(btnAddRole)', function (data) {
                loading = layer.load();
                var oldepass = jq('#oldepass').val();           //旧密码
                var id = localStorage.getItem("userid");        //当前用户ID
                //获取当前用户,判断当前输入的旧密码是否正确
                jq.ajax({
                    type: 'post',
                    url: '/api/Users/UsById?id=' + id,
                    success: function (res) {
                        var userInfo = res;
                        if (userInfo.User_Password != oldepass) {
                            layer.msg("旧密码不正确!");
                        } else
                        {
                            if (jq('#newpass').val() != jq('#agenpass').val()) {
                                layer.msg("新密码和确认密码不一致!");
                            } else {
                                var users =
                                    {
                                        User_Id: id,
                                        User_Password: jq('#agenpass').val(),
                                        User_UserName: userInfo.User_UserName,
                                        User_RealName: userInfo.User_RealName,
                                        User_CreateDate: userInfo.User_CreateDate,
                                        User_CreateName: userInfo.User_CreateName,
                                    }
                                //修改当前用户密码
                                jq.ajax({
                                    type: 'post',
                                    url: '/api/Users/UpdatePassWord',
                                    contentType: "application/json",
                                    data: JSON.stringify(users),
                                    dataType: "json",
                                    success: function (mesg) {
                                        if (mesg.AnswerType == 1) {
                                            layer.msg(mesg.AnswerMeg + ",请重新登录！");
                                            localStorage.clear("username");
                                            localStorage.clear("userid");
                                            window.location.href = "login.html";
                                        }
                                        layer.msg(mesg.AnswerMeg, function () {
                                            location.reload();
                                            return false;
                                        });
                                    }
                                });
                            }
                        }
                    }
                });
            });
        });
    </script>
</body>
</html>